package com.appkubes.fintech.restful.application.data.contact.service.impl;

import com.appkubes.fintech.core.po.FintechDataContact;
import com.appkubes.fintech.restful.application.data.contact.dao.DataContactDao;
import com.appkubes.fintech.restful.application.data.contact.entity.vo.ContactCollectVO;
import com.appkubes.fintech.restful.application.data.contact.service.DataCollectService;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Rongjie
 * @Date: 2020/1/13 0:14
 * @Description:
 */
@Service
@Data
public class CollectionServiceData implements DataCollectService {

    @Resource
    DataContactDao contactDao;

    @Override
    public Integer contactData(ContactCollectVO contactCollectVO) {

        List<Integer> result = contactCollectVO.getContactEOList().stream().map(contactEO -> {
            FintechDataContact dataContact = new FintechDataContact();
            BeanUtils.copyProperties(contactEO, dataContact);
            dataContact.setAppKey(contactCollectVO.getAppKey());
            dataContact.setUserKey(contactCollectVO.getUserKey());
            return contactDao.insertSelective(dataContact);
        }).collect(Collectors.toList());

        return result.size();
    }
}
